import { welcomeRouteMenuStructuredData, welcomeBtnsPerm } from './welcome-perms-config';
import { sysManagementRouteMenuStructuredData, sysManagementBtnsPerm } from './sys-management-perms-config';
//id:importRbacRouteConfig
// import { rbacRouteConfig as rbacRouteMenuStructuredData,rbacBtnPermsMap as rbacBtnsPerm} from '@/config/perms/rbac-perms-config';
//遍历所有权限，平铺返回
const getAllPermsList = (routeMenuStructuredData, btnsPermsList) => {
    const allPerms = [];
    //遍历 routeMenuStructuredData
    const pushPerms = (list) => {
        if (Array.isArray(list) && list.length) {
            list.forEach((item) => {
                const children = item.children;
                allPerms.push({ ...item, children: undefined });
                pushPerms(children);
            });
        }
        return list;
    };

    //
    const pushBtnsPerms = (list) => {
        if (Array.isArray(list) && list.length > 0) {
            list.forEach((btnsPermObj) => {
                for (const permsKey in btnsPermObj) {
                    allPerms.push({ ...btnsPermObj[permsKey], permsKey });
                }
            });
        }
    };

    pushPerms(routeMenuStructuredData);
    pushBtnsPerms(btnsPermsList);
    return allPerms;
};

const getPermsMap = (allPermsListInner) => {
    const permsMapInner = {};
    allPermsListInner.forEach((item) => {
        permsMapInner[item.permsKey] = item;
    });
    return permsMapInner;
};

//结构化的路由菜单数据
export const routeMenuStructuredData = [welcomeRouteMenuStructuredData, sysManagementRouteMenuStructuredData /*rbacRouteMenuStructuredDataPlaceHold*/];
export const allPermsList = getAllPermsList(routeMenuStructuredData, [welcomeBtnsPerm, sysManagementBtnsPerm /*rbacBtnsPermPlaceHold*/]);
export const permsMap = getPermsMap(allPermsList);
